import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class CupertinoTabBarDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => CupertinoTabBarState();
}

class CupertinoTabBarState extends State<CupertinoTabBarDemo> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      //底部按钮
      tabBar: _cupertinotabbar(),
      tabBuilder: (context, index) {
        return CupertinoPageScaffold(
            child: ListView(
              children: [],
            ),
          navigationBar: CupertinoNavigationBar(
            middle: Text('第${index}个'),
          ),
        );
      },


    );
  }

  CupertinoTabBar _cupertinotabbar() {
    return CupertinoTabBar(
      onTap: (index) {
        print('index');
      },
      //默认选中位置
      currentIndex: 0,
      //tabbar 背景色
      backgroundColor: Colors.lightBlueAccent,
      //图标高亮颜色
      activeColor: Colors.blue,
      //图标未选中颜色
      inactiveColor: Colors.grey,
      //图标大小
      iconSize: 30,
      //边框
      border: Border(
          top: BorderSide(
              width: 3,
              color: Colors.white
          )

      ),
      items: [
        _bottomNavigationBarItem(Image.asset('images/index_02.png'),
            Image.asset('images/index_01.png'), '劳务'),
        _bottomNavigationBarItem(
            Image.asset('images/mine_02.png'), Image.asset('images/mine_01.png'),
            '我的'),
      ],

    );
  }

  BottomNavigationBarItem _bottomNavigationBarItem(Image activityIcon,
      Image unactivityIcon, String title) {
    return BottomNavigationBarItem(
        icon: unactivityIcon,
        activeIcon: activityIcon,
        label: title,
        backgroundColor: Colors.yellow
    );
  }
}
